//
//  HTInputViewController.m
//  TruckDriver
//
//  Created by Ting Han on 2017/9/29.
//  Copyright © 2017年 Ting Han. All rights reserved.
//

#import "HTInputViewController.h"

@interface HTInputViewController ()
@property (nonatomic,strong) UITextField *textField;
@end

@implementation HTInputViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNavi];
    [self setupMain];
}
- (void)setupMain{
    self.view.backgroundColor = [UIColor whiteColor];
    self.textField = [[UITextField alloc]initWithFrame:CGRectMake(2, 0, kHTScreenWidth-4, kWidth(50))];
    [self.view addSubview:self.textField];
    self.textField.borderStyle = UITextBorderStyleNone;
    self.textField.font = [UIFont systemFontOfSize:15.0f];
    self.textField.layer.masksToBounds = YES;
    self.textField.layer.cornerRadius = 4;
    self.textField.layer.borderWidth = .3;
    self.textField.layer.borderColor = [UIColor lightGrayColor].CGColor;
    CGRect frame = [self.textField frame];
    frame.size.width = 20.0f;
    UIView *leftview = [[UIView alloc] initWithFrame:frame];
    self.textField.leftViewMode = UITextFieldViewModeAlways;
    self.textField.leftView = leftview;
    switch (self.type) {
        case InputTypeName:
        {
            self.title = @"驾驶员姓名";
            self.textField.placeholder = @"请填写姓名";
        }
        break;
        case InputTypeCard:
        {
            self.title = @"身份证号";
            self.textField.placeholder = @"请填写身份证号";
        }
        break;
        case InputTypeHeavy:
        {
            self.title = @"载重";
            self.textField.placeholder = @"请填写载重(吨)";
        }
        break;
        default:
        break;
    }
}
- (void)setupNavi{
    UIBarButtonItem *right = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStyleDone target:self action:@selector(didClickNavRight:)];
    self.navigationItem.rightBarButtonItem = right;
}
- (void)didClickNavRight:(id)sender{
    switch (self.type) {
        case InputTypeName:
        {
            if (self.textField.text == nil || self.textField.text.length <= 0) {
                [HTShowUtil showMessage:@"请输入姓名"];
                return;
            }
            if (self.delegate && [self.delegate respondsToSelector:@selector(didInputMessage:withType:)]) {
                 [self.delegate didInputMessage:self.textField.text withType:InputTypeName];
            }
              [self.navigationController popViewControllerAnimated:YES];
           
        }
            break;
        case InputTypeCard:
        {
            if (self.textField.text == nil || self.textField.text.length <= 0) {
                [HTShowUtil showMessage:@"请输入身份证号"];
                return;
            }
            if (self.delegate && [self.delegate respondsToSelector:@selector(didInputMessage:withType:)]) {
                [self.delegate
                 didInputMessage:self.textField.text withType:InputTypeCard];
            }
            [self.navigationController popViewControllerAnimated:YES];
        }
            break;
        case InputTypeHeavy:
        {
            if (self.textField.text == nil || self.textField.text.length <= 0) {
                [HTShowUtil showMessage:@"请输入载重"];
                return;
            }
            if (self.delegate && [self.delegate respondsToSelector:@selector(didInputMessage:withType:)]) {
                
                [self.delegate didInputMessage:[NSString stringWithFormat:@"%@",self.textField.text]  withType:InputTypeHeavy];
            }
            [self.navigationController popViewControllerAnimated:YES];
           
        }
            break;
        default:
            break;
    }
    
   
}
@end
